/* 2017-9-28 16:04:24 | 修改 木遥（微信:  http://marsgis.cn/weixin.html ） */
//模块：
mars3d.widget.bindClass(mars3d.widget.BaseWidget.extend({
    options: {
        //弹窗
        view: {
            type: "window",
            url: "view.html",
            windowOptions: {
                width: 250,
                height: 270
            }
        },
    },
    drawControl: null,
    //初始化[仅执行1次]
    create: function () {
        this.drawControl = new mars3d.Draw(this.viewer, { hasEdit: false });
        this.floodControl = new mars3d.analysi.FloodByEntity(viewer);

    },
    viewWindow: null,
    //每个窗口创建完成后调用
    winCreateOK: function (opt, result) {
        this.viewWindow = result;
    },
    //打开激活
    activate: function () {

    },
    //关闭释放
    disable: function () {
        this.viewWindow = null;
        this.clear();
    },
    drawPolygon: function () {
        var that = this;
        this.clear();

        this.drawControl.startDraw({
            type: "polygon",
            style: {
                color: "#007be6",
                opacity: 0.5,
                perPositionHeight: true,
                outline: false
            },
            success: function (entity) { //绘制成功后回调
                that.drawOk(entity);
            }
        });
    },
    entity: null,
    drawOk: function (entity) {
        if (this.viewWindow == null) return;

        this.entity = entity;

        //求最大、最小高度值  
        var positions = this.drawControl.getPositions(entity);
        var result = mars3d.polygon.getHeightRange(positions, viewer.scene);
        this.viewWindow.updateHeightForDraw(result.minHeight, result.maxHeight);
    },

    startFx: function (params) {
        if (this.entity == null) {
            haoutil.msg('请首先绘制分析区域！');
            return false;
        }

        this.floodControl.start(this.entity, params);
        return true;
    },
    clear: function () {
        this.floodControl.clear();

        this.drawControl.deleteAll();
        this.entity = null;
    },



}));

